package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.ProductsMapper;
import com.ming.easyDevelop.entity.po.Products;
import com.ming.easyDevelop.entity.query.ProductsQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.ProductsService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import java.math.BigDecimal;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("productsService")
public class ProductsServiceImpl implements ProductsService {
	private final ProductsMapper<Products, ProductsQuery> productsMapper;

	public ProductsServiceImpl(ProductsMapper productsMapper){
		this.productsMapper = productsMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Products> findListByParam(ProductsQuery query){
		return this.productsMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(ProductsQuery query){
		return this.productsMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Products> findListByPage(ProductsQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Products> res = this.findListByParam(query);
		return new PaginationResVo<Products>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Products> list){
		return this.productsMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Products bean){
		return this.productsMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Products bean){
		return this.productsMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Products> list){
		return this.productsMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据ProductID查询
	 */
	@Override
	public Products getByProductID(Integer productID){
		return this.productsMapper.selectByProductID(productID);
	}

	/**
	 * 根据ProductID更新
	 */
	@Override
	public Long updateByProductID(Products bean, Integer productID){
		return this.productsMapper.updateByProductID(bean,productID);
	}

	/**
	 * 根据ProductID删除
	 */
	@Override
	public Long deleteByProductID(Integer productID){
		return this.productsMapper.deleteByProductID(productID);
	}

	/**
	 * 根据ProductNameAndCategoryID查询
	 */
	@Override
	public Products getByProductNameAndCategoryID(String productName, Integer categoryID){
		return this.productsMapper.selectByProductNameAndCategoryID(productName, categoryID);
	}

	/**
	 * 根据ProductNameAndCategoryID更新
	 */
	@Override
	public Long updateByProductNameAndCategoryID(Products bean, String productName, Integer categoryID){
		return this.productsMapper.updateByProductNameAndCategoryID(bean,productName, categoryID);
	}

	/**
	 * 根据ProductNameAndCategoryID删除
	 */
	@Override
	public Long deleteByProductNameAndCategoryID(String productName, Integer categoryID){
		return this.productsMapper.deleteByProductNameAndCategoryID(productName, categoryID);
	}

}
